package innerSortRealize

/**
 * @author liujun
 * @version 1.0
 * @date 2021-06-20 13:09
 * @author—Email liujunfirst@outlook.com
 * @blogURL https://blog.csdn.net/ljfirst
 * @description 插入排序
 */

type InsertSort struct {
}

func (s *InsertSort) SortMethod(array []int) (arr []int) {
	if len(array) == 0 || len(array) == 1 {
		return array
	}
	for i := 0; i < len(array)-1; i++ {
		flag := i + 1
		temp := array[flag]
		for ; flag-1 >= 0; flag-- {
			if array[flag-1] > temp {
				array[flag] = array[flag-1]
			} else {
				break
			}
		}
		if flag != i+1 {
			array[flag] = temp
		}
	}
	return array
}
